<template>
  <div class="all-job-resume">
    <div class="all-job-resume-head">
      <el-col :span="23">
        <span class="all-job-resume-line"></span>
        工作经历
        <span class="all-job-resume-sub-text">必填</span>
      </el-col>
      <el-col :span="1" v-if="data.length < 5">
        <i class="el-icon-circle-plus plus-add" @click="addContent"></i>
      </el-col>
    </div>

    <work-experience-list
      v-for="(item,index) in data"
      :data="item"
      :key="index"
      :form="form"
      :enterpriseType="enterpriseType"
      :practiceType="practiceType"
      @on-pitch="cancel"
    ></work-experience-list>

    <div class="edit-content" v-if="form.sta == 2 && form.editSta == -1">
      <div class="all-job-resume">
        <el-form label-width="100px" label-position="right">
          <el-row>
            <el-col :span="12">
              <el-form-item label="企业名称">
                <el-input class="theme-input all-input" v-model="params.companyName"></el-input>
              </el-form-item>
              <el-form-item label="执业类型">
                <!-- <el-select class="all-input" v-model="params.licenseType">
                  <el-option
                    v-for="(item,index) in practiceType"
                    :label="item.content"
                    :value="item.id"
                    :key="index"
                  ></el-option>
                </el-select>-->
                <el-cascader
                  :options="practiceType||[]"
                  :props="props"
                  v-model="params.licenseType"
                ></el-cascader>
              </el-form-item>
              <el-form-item label="所在城市">
                <!-- <el-select class="all-input" v-model="params.workCity">
                  <el-option v-for="(item,index) in city" :label="item" :value="item" :key="index"></el-option>
                </el-select>-->
                <el-cascader :options="city" @change="getData"></el-cascader>
              </el-form-item>
            </el-col>
            <el-col :span="11" :offset="1">
              <el-form-item label="职位名称">
                <el-input class="theme-input all-input" v-model="params.jobName"></el-input>
              </el-form-item>
              <el-form-item label="企业类型">
                <el-select class="all-input" v-model="params.companyType">
                  <el-option
                    v-for="(item,index) in enterpriseType"
                    :label="item.content"
                    :value="item.id"
                    :key="index"
                  ></el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="任职时间">
                <el-date-picker
                  :editable="false"
                  class="resume-datepicker"
                  type="monthrange"
                  value-format="yyyy-MM"
                  range-separator="至"
                  start-placeholder="开始日期"
                  end-placeholder="结束日期"
                  v-model="params.time"
                ></el-date-picker>
              </el-form-item>
            </el-col>
          </el-row>
          <el-form-item label="工作内容">
            <el-input type="textarea" placeholder="请输入" v-model="params.jobContent"></el-input>
          </el-form-item>
          <el-form-item class="form-button-right">
            <el-button class="ghost-button" @click="cancel">取消</el-button>
            <el-button class="submit-button" @click="doSubmit">确认</el-button>
          </el-form-item>
        </el-form>
      </div>
    </div>
  </div>
</template>

<script>
import workExperienceList from './list/work-experience-list'
import { chinaOptions, CodeToText, TextToCode } from '@/assets/utils/china.js'
export default {
  props: ['form', 'enterpriseType', 'practiceType', 'data'],
  data() {
    return {
      city: chinaOptions,

      params: {
        id: '',
        companyName: '',
        companyType: '',
        licenseType: [],
        jobName: '',
        workCity: '',
        time: [],
        jobContent: ''
      },
      props: {
        value: 'licenseTypeId',
        children: 'licenseSonList',
        label: 'licenseType'
      },
      pickerOptions: {
        shortcuts: [
          {
            text: '今年至今',
            onClick(picker) {
              const end = new Date()
              const start = new Date(new Date().getFullYear(), 0)
              picker.$emit('pick', [start, end])
            }
          }
        ]
      }
    }
  },
  methods: {
    check() {
      if (
        this.params.companyName == '' ||
        this.params.companyType == '' ||
        this.params.licenseType == '' ||
        this.params.jobName == '' ||
        this.params.workCity == '' ||
        this.params.time == '' ||
        this.params.jobContent == ''
      ) {
        _g.message('数据不能为空', 'warning')
        return false
      }
      return true
    },
    addContent() {
      //点击添加按钮
      this.form.sta = 2
      this.form.editSta = -1
    },
    cancel() {
      //点击添加按钮
      this.$emit('on-pitch', true)
      this.form.sta = -1
      this.form.editSta = -1
    },
    doSubmit() {
      //点击确定

      if (!this.check()) return false
      let params = {
        id: this.params.id,
        companyName: this.params.companyName,
        companyType: this.params.companyType,
        licenseType: this.params.licenseType[1],
        jobName: this.params.jobName,
        jobContent: _g.getTextAreaTo(this.params.jobContent),
        workCity: this.params.workCity,
        jobStartTime: this.params.time[0],
        jobEndTime: this.params.time[1]
      }
      _g.apiPost('/talent/updateWorkExperience.do', params).then(res => {
        _g.toMessage(res)
        this.cancel()
        this.emptyData()
      })
    },
    getData(val) {
      //console.log(val)
      // let l = []
      // for (let i in val) {
      //   l.push(CodeToText[val[i]])
      // }
      this.params.workCity = val.join('-')
    },
    emptyData() {
      this.params.id = ''
      this.params.companyName = ''
      this.params.companyType = ''
      this.params.licenseType = []
      this.params.jobName = ''
      this.params.jobContent = ''
      this.params.workCity = ''
      this.params.time = []
    }
  },
  components: {
    workExperienceList
  }
}
</script>

<style lang="scss" scoped>
</style>
